/*
 * @Author: your name
 * @Date: 2021-11-15 09:49:50
 * @LastEditTime: 2021-11-15 15:15:20
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \flutter_redux\redux_example\lib\widgets\add.dart
 */
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux_example/store/actions.dart';
import 'package:redux_example/store/state.dart';
import 'package:redux_example/widgets/view_model.dart';

class Add extends StatefulWidget {
  final ViewModel viewModel;
  const Add(
    this.viewModel, {
    Key? key,
  }) : super(key: key);

  @override
  State<Add> createState() => _AddState();
}

class _AddState extends State<Add> {
  TextEditingController controller = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return TextField(
      controller: controller,
      decoration: const InputDecoration(
        hintText: '请输入待办事项',
      ),
      onSubmitted: (String s) {
        print('用户输入了$s');
        print('用户输入了${controller.value}');
        // callback();
        widget.viewModel.addItem(controller.text);
        controller.text = '';
      },
    );
  }
}
